From 761cb55b43858c74dfa7db64bc49d59294f84874 Mon Sep 17 00:00:00 2001 From: =?utf8?q?=C3=98yvind=20Kol=C3=A5s?= Date: Sun, 11 Sep 2005 12:15:17 +0000 Subject: [PATCH] added loss calculation --- ChangeLog | 6 ++ tests/Makefile.am | 4 +- tests/formats.c | 158 ++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 167 insertions(+), 1 deletion(-) create mode 100644 tests/formats.c diff --git a/ChangeLog b/ChangeLog index ddc1ee6..25ae69e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2005-09-11 Øyvind Kolås + + * tests/formats.c: new test (that might form the basis of loss + calculations done for ranking of formats). + * tests/Makefile.am: added new test + 2005-09-11 Øyvind Kolås * extensions/CIE-Lab.c: (formats): s/cie-lab-u16/CIE Lab u16/ diff --git a/tests/Makefile.am b/tests/Makefile.am index 51bfaf5..c0910e9 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -9,10 +9,11 @@ TESTS = \ rgb_to_ycbcr \ srgb_to_lab_u8 \ sanity \ + babl_class_name \ conversions \ types \ models \ - babl_class_name + formats TESTS_ENVIRONMENT = BABL_PATH=$(top_builddir)/extensions @@ -23,6 +24,7 @@ rgb_to_ycbcr_SOURCES = rgb_to_ycbcr.c babl_class_name_SOURCES = babl_class_name.c sanity_SOURCES = sanity.c types_SOURCES = types.c +formats_SOURCES = formats.c models_SOURCES = models.c diff --git a/tests/formats.c b/tests/formats.c new file mode 100644 index 0000000..b5f3146 --- /dev/null +++ b/tests/formats.c @@ -0,0 +1,158 @@ +/* perform a symmetricality of conversion test on a set of randomized + * RGBA data */ + +#include +#include +#include "babl-internal.h" + +int OK=1; + +#define pixels 1024 +#define TOLERANCE 0.001 + +double test[pixels * 4]; + +double r_interval (double min, double max) +{ + long int rand_i = random (); + double ret; + ret = (double) rand_i / RAND_MAX; + ret*=(max-min); + ret+=min; + return ret; +} + +void test_init (void) +{ + double r_min = 0.0, + r_max = 1.0, + g_min = 0.0, + g_max = 1.0, + b_min = 0.0, + b_max = 1.0, + a_min = 0.0, + a_max = 1.0; + int i; + double r,g,b,a; + for (i=0;iformat.bytes_per_pixel); + clipped = babl_calloc (pixels, ref_fmt->format.bytes_per_pixel); + destination = babl_calloc (pixels, fmt->format.bytes_per_pixel); + transformed = babl_calloc (pixels, ref_fmt->format.bytes_per_pixel); + + babl_process (fish_to, test, original, pixels); + babl_process (fish_from, original, clipped, pixels); + babl_process (fish_to, clipped, destination, pixels); + babl_process (fish_from, destination, transformed, pixels); + + { + int i; + int log=0; + double loss=0.0; + + for (i=0;iTOLERANCE) + { + if (!log) + log=1; + OK=0; + } + } + if (log && log < 5) + { + babl_log ("%s", babl->instance.name); + babl_log ("\ttest: %2.3f %2.3f %2.3f %2.3f", test [i*4+0], + test [i*4+1], + test [i*4+2], + test [i*4+3]); + babl_log ("\tclipped: %2.3f %2.3f %2.3f %2.3f", clipped [i*4+0], + clipped [i*4+1], + clipped [i*4+2], + clipped [i*4+3]); + babl_log ("\ttrnsfrmd: %2.3f %2.3f %2.3f %2.3f", transformed [i*4+0], + transformed [i*4+1], + transformed [i*4+2], + transformed [i*4+3]); + log++; + OK=0; + } + } + loss /= pixels; + { + babl_log ("%s\tloss:%f%%", babl->instance.name, loss * 100.0); + OK = 0; + } + } + + babl_free (original); + babl_free (clipped); + babl_free (destination); + babl_free (transformed); + return 0; +} + +int main (void) +{ + babl_init (); + test_init (); + + babl_set_extender (babl_extension_quiet_log ()); + babl_format_each (format_check, NULL); + + babl_destroy (); + + return !OK; +} -- 2.30.2